import { reqgetGoodInfo, reqaddOrUpdateShopCart } from "@/api";
import { getUUID } from '@/utils/uuid_token';

const state = {
  goodInfo: {},
  uuid_token: getUUID()
};
const mutations = {
  GETGOODINFO (state, goodInfo) {
    state.goodInfo = goodInfo;
  }
};
const actions = {
  async getGoodInfo ({ commit }, skuId) {
    let result = await reqgetGoodInfo(skuId);
    if (result.code == 200) {
      commit('GETGOODINFO', result.data);
    }
  },
  async addOrUpdateShopCart ({ commit }, { skuId, skuNum }) {
    let result = await reqaddOrUpdateShopCart(skuId, skuNum);
    if (result.code == 200) {
      return "请求成功了"
    } else {
      /*       return Promise.reject(new Error("faile"));
       */
      return 'ok'
    }
  }
};
const getters = {
  categoryView () {
    return state.goodInfo.categoryView || {}
  },
  skuInfo () {
    return state.goodInfo.skuInfo || {}
  },
  spuSaleAttrList () {
    return state.goodInfo.spuSaleAttrList || []
  }
};

export default {
  state,
  mutations,
  actions,
  getters
}